﻿using System;
using Microsoft.Practices.Unity;
using TestByWire.AttributeHandlers;

namespace TestByWire
{
    internal class UseFakeInteraction : IContainerInteraction
    {
        private readonly object _instance;

        public UseFakeInteraction(Type registrationType, object instance)
        {
            RegistrationType = registrationType;
            RegistrationName = null;
            _instance = instance;
        }

        public Type RegistrationType { get; private set; }
        public string RegistrationName { get; private set; }

        public void Execute(IBuildContext buildContext)
        {
            if (buildContext.TestTarget != null)
            {
                return;
            }

            buildContext.Container.RegisterInstance(RegistrationType, RegistrationName, _instance, new ExternallyControlledLifetimeManager());
        }
    }
}
